import {GetMenuData_ACTION, ChangeOpenKey_ACTION, SiderCollapsed_ACTION, TabsActiveKey_ACTION} from "../actionType";
import {AddTabsPane_ACTION, ChangeTabsData_ACTION} from "../actionType";

// 获取menu数据
export const getMenuData = () => {
    // 在这里请求menu数据
    let list = [{key : "sub1", type: "", title: "基础信息", routes: [
            {key : "sub1_1", type: "", title: "基础信息"},
            {key : "sub1_2", type: "", title: "基础信息"},
            {key : "sub1_3", type: "", title: "基础信息"},
            {key : "sub1-4", type: "", title: "基础信息"},
            {key : "sub1—5", type: "", title: "基础信息"},
        ]},
        {key : "sub2", type: "", title: "采购管理", routes: [
                {key : "sub2_1", type: "", title: "基础信息"},
                {key : "sub2_2", type: "", title: "基础信息"},
                {key : "sub2_3", type: "", title: "基础信息"},
                {key : "sub2-4", type: "", title: "基础信息"},
                {key : "sub2—5", type: "", title: "基础信息"},
            ]},
        {key : "sub3", type: "", title: "销售管理", routes: [
                {key : "sub3_1", type: "", title: "基础信息"},
                {key : "sub3_2", type: "", title: "基础信息"},
                {key : "sub3_3", type: "", title: "基础信息"},
                {key : "sub3-4", type: "", title: "基础信息"},
                {key : "sub3—5", type: "", title: "基础信息"},
            ]},
        {key : "sub4", type: "", title: "销售管理1"},
        {key : "sub5", type: "", title: "销售管理2"},
        {key : "sub6", type: "", title: "销售管理3"},
        {key : "sub7", type: "", title: "销售管理4"}
    ];
    let rootKeys = list.map(item => {
        return item.key
    });
    return {
        type: GetMenuData_ACTION,
        menuList: list,
        rootKeys
    }
}

// 设置menu展开的key
export const changeOpenKey = (openKey) => {
    return {
        type: ChangeOpenKey_ACTION,
        openKey
    }
}

// 切换sider的展开回收状态
export const toggleCollapsed = {type: SiderCollapsed_ACTION}

// menu点击向tabs添加pane
export const onClick = (key, title) => {
    return {
        type: AddTabsPane_ACTION,
        key,
        title
    }
}

// 切换tabs的数据
export const changeTabsData = (panes, activeKey) => {
    return {
        type: ChangeTabsData_ACTION,
        tabsList: panes,
        activeKey
    }
}
